package cn.edu.neu.softlab633.influencemaximization.sy.M_TLTGreedy;

import cn.edu.neu.softlab633.influencemaximization.sy.bean.Graph;
import cn.edu.neu.softlab633.influencemaximization.sy.bean.Index;
import cn.edu.neu.softlab633.influencemaximization.sy.bean.Potentiality;
import cn.edu.neu.softlab633.influencemaximization.sy.datapreprocessing.InfluenceCal.InfluenceCal;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;

/**
 * Created by Jason on 2017/5/11.
 */
public class M_Potentiality {
    public static ArrayList<Potentiality> calPotentiality(double threshold, Double[] query, Graph graph) {
        Index index = graph.getOutgoingIndex();
        ArrayList<Potentiality> potentialities = new ArrayList<>();
        for (Map.Entry<Integer, Map<Integer, Double[]>> integerArrayListEntry : index.getIndex().entrySet()) {
            double pot = 0;
            for (Map.Entry<Integer, Double[]> integerEntry : integerArrayListEntry.getValue().entrySet()) {
                pot += InfluenceCal.calInfluence(query, integerEntry.getValue());
            }
            pot /= threshold;
            potentialities.add(new Potentiality(integerArrayListEntry.getKey(), pot));
        }
        Collections.sort(potentialities);
        return potentialities;
    }
}
